package http

import (
	"gitee.com/saxon134/go-utils/saData"
	"gitee.com/saxon134/go-utils/saLog"
	"gitee.com/saxon134/workflow/conf"
	"gitee.com/saxon134/workflow/http/middleware"
	"github.com/gin-gonic/gin"
)

// Init
// @Description: 初始化路由，会阻塞
func Init() {
	gin.SetMode(gin.ReleaseMode)

	g := gin.New()
	g.Use(gin.Recovery())
	g.Use(middleware.Cors())

	//初始化路由
	{
		Gett(g.Group(""), "", Index)
		Gett(g.Group("index"), "", Index)
		Gett(g.Group("workapi"), "", Index)
		initRoutes(g.Group("workapi"))
	}

	saLog.Log("[HTTP] Listening on: " + saData.String(conf.Conf.Http.Port))
	err := g.Run("0.0.0.0:" + saData.String(conf.Conf.Http.Port))
	if err != nil {
		panic("[HTTP] start error:" + err.Error())
	}
}
